package demo.cor;

import java.util.ArrayList;
import java.util.List;

public class ApplicationFilterChain implements FilterChain {
  // 表示 从数组移动的索引
  private int pos = 0;
  private final List<Filter> filters = new ArrayList<>();
  
  @Override
  public void doFilter(Request request, Response response) {
    if (filters.size() > pos) {
      Filter filter = filters.get(pos++);
      filter.doFilter(request, response, this);
    } else {
      System.out.println("filter 过滤器执行结束.");
    }
  }
  
  @Override
  public void addFilter(Filter filter) {
    filters.add(filter);
  }
}
